﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MaxLeaf.Platform.Contract;
using MaxLeaf.Platform.DataContract;
using CommonsLib.DB;
using System.Transactions;
using System.Data.SqlClient;
using System.Data.Common;
using System.Diagnostics;
using CommonsLib.Settings;
using MaxLeaf.Platform.Functions;

namespace MaxLeaf.Platform.DALImplementation
{
    public class TestDAL :BaseDAL, ITest
    {
        public TestDataModel SayHello(TestDataModel user)
        {
           
            //TestUpdate(user);

            string[] cs = user.Name.Split(' ');
            Array.Reverse(cs);


            user.Name = string.Format("{0}",string.Join(" ",cs));

            return user;
        }

        private void TestUpdate(TestDataModel user)
        {
            //ConnectionInfo a = GetConnectionInfo("DB_A");
            //ConnectionInfo b = GetConnectionInfo("DB_B");
            //DBAccess conA = new DBAccess(a);
            //DbDataReader dr = conA.GetDataReader("select name from  a order by id desc");
            //while (dr.Read())
            //{
            //    Debug.WriteLine(dr.GetString(0));
            //}
            //dr.Close();


            //System.Transactions.TransactionOptions txOps = new TransactionOptions();
            //txOps.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            //txOps.Timeout = TimeSpan.FromSeconds(60000);

            //using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required, txOps))
            //{

            //    DBAccess conA = new DBAccess(a);
            //    DBAccess conB = new DBAccess(b);
            //    try
            //    {

            //        conA.ExecuteSql("insert into a(name) values('" + user.Name + "1')");
            //         conB.ExecuteSql("insert into a(name) values('" + user.Name + "2')");

                    
            //        //Scope complete, commit work.
            //        tx.Complete();

            //    }
            //    catch
            //    {

            //        throw;
            //    }
            //    finally
            //    {
                    
                    

            //    }
            //}
        }

        public string ShowError(string strName)
        {
            throw new MaxLeaf.Platform.Commons.MaxLeafException("Test 有错误发生");

        }


 
    }
}
